package org.qydjk.console.service.impl;

import org.qydjk.common.dao.IBaseDao;
import org.qydjk.common.pojo.SellerProductLabelDetail;
import org.qydjk.common.service.impl.BaseService;
import org.qydjk.common.util.StringUtil;
import org.qydjk.common.vo.EasyUIResponse;
import org.qydjk.common.vo.HibernatePage;
import org.qydjk.console.service.ISellerProductLabelDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/12/12 0012.
 */
@Service
public class SellerProductLabelDetailService extends BaseService implements ISellerProductLabelDetailService {
    @Autowired
    private IBaseDao baseDao;
    /****
     * 带分页查询和筛选标签明细
     * @author Edward_yang
     * @uptime 2017-12-12
     * @param page 当前页
     * @param rows 每页多少条
     * @param sellerProductLabelCode  联动
     * @param keyWord 查询条件
     * @return
     */
    public EasyUIResponse findLabelDetailList(Integer page, Integer rows, String sellerProductLabelCode, String keyWord) throws  Exception{
        HibernatePage pager = new HibernatePage(page,rows);
        String sql="select * from qy_seller_product_label_detail qspld where 1=1 ";
        String hqlCount="select count(spld.id) from SellerProductLabelDetail spld where 1=1 ";
        //联动
        if(!StringUtil.isEmptyOrNull(sellerProductLabelCode)){
            sql+=" and qspld.seller_product_label_code="+sellerProductLabelCode;
            hqlCount+=" and spld.sellerProductLabelCode='"+sellerProductLabelCode+"'";
        }
        //查询
        if(!StringUtil.isEmptyOrNull(keyWord)){
            sql+="  and qspld.name like '%"+keyWord+"%' or  qspld.code like '%"+keyWord+"%'";
            hqlCount+=" and spld.name like '%"+keyWord+"%' or  spld.code like '%"+keyWord+"%'";
        }
        sql+= " order by qspld.ord desc ";

            List<SellerProductLabelDetail> sellerProductLabelDetailList =baseDao.findBySQL(sql, SellerProductLabelDetail.class,pager);
            int total = baseDao.getRecordCountHQL(hqlCount);
            return new EasyUIResponse(total,sellerProductLabelDetailList);
    }
}
